package com.library.dao.impl;

import com.library.bean.Book;
import com.library.dao.BaseDao;
import com.library.dao.BookDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author:max
 * @Date: 2024/9/14 17:25
 * @Description:
 */


public class BookDaoImpl extends BaseDao implements BookDao {

    @Override
    public List<Book> SelectBookAll() {
        // TODO Auto-generated method stub
        Connection con = null;
        PreparedStatement pstm = null;
        ResultSet res = null;
        String sql = "SELECT * FROM book";
        System.out.println(sql);
        List<Book> list=new ArrayList<Book>();
        try {
            con = BaseDao.getConnection();
            pstm = con.prepareStatement(sql);
            res = pstm.executeQuery();
            while(res.next()) {
                Book book = new Book();
                book.setBookId(res.getInt("bookId"));
                book.setBookName(res.getString("bookName"));
                book.setBookType(res.getString("bookType"));
                book.setBookWriter(res.getString("bookWriter"));
                list.add(book);
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally {
            BaseDao.closeAll(con,pstm,res);
        }
        return list;
    }
}
